package algorithm.bitset;


/**
 * <p>
 * com.google.common.hash.BloomFilter
 *
 * <dependency>
 * <groupId>com.google.guava</groupId>
 * <artifactId>guava</artifactId>
 * <version>31.0.1-jre</version>
 * </dependency>
 * </p>
 *
 * @author liyi
 * @since 2024/4/19 15:01
 */
public class BloomFilterTest {
    public static void main(String[] args) {
        int datasize = 100000000;    //我们要插入的数据也就是n
        double fpp = 0.001;        //0.1%	误判率

        com.google.common.hash.BloomFilter<Integer> bloomFilter = com.google.common.hash.BloomFilter.create(com.google.common.hash.Funnels.integerFunnel(), datasize, fpp);

        long start = System.currentTimeMillis();
        for (int i = 0; i < 100000000; i++) {
            bloomFilter.put(i);
        }
        System.out.println((System.currentTimeMillis() - start) + ":ms");


        //怎么测试这个误判率
        int t = 1;
        for (int i = 20000000; i < 30000000; i++) {
            if (bloomFilter.mightContain(i)) {
                System.out.println("误判的个数:" + t);
                t++;
            }
        }
    }
}

